﻿using CSharpDay13Nov10.Adapters.Interfaces;
using CSharpDay13Nov10.Data;
using CSharpDay13Nov10.Data.Model;
using CSharpDay13Nov10.Models;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace CSharpDay13Nov10.Adapters.Adapters
{
    public class UserAdapter : IUserAdapter
    {
        public void RegisterUser(NewUserVM user)
        {
            using(ApplicationDbContext db = new ApplicationDbContext()) {
                var store = new UserStore<ApplicationUser>(db);
                var manager = new UserManager<ApplicationUser>(store);
                ApplicationUser newUser = new ApplicationUser() {
                    UserName = user.Username,
                    Email = user.Email
                };
                manager.Create(newUser, user.Password);
                manager.AddToRole(newUser.Id, "User");
                db.SaveChanges();
            }
        }
    }
}